import pathToRegexp from 'path-to-regexp/index';
import {getGZT,getGZL,getGZLList,getGZLTow,getworking,getworkingList,getTaskData,postTaskData} from 'services/app';
let dispatchApp = null;
import { Modal } from 'antd';
export default {
    namespace: 'dashboard',
    state: {
        bodyWidth:document.body.clientWidth,
        fist:{},
    },
    subscriptions: {
        setupHistory ({ dispatch, history }) {
            dispatchApp = dispatch;
            history.listen((location) => {
                const match = pathToRegexp('/home').exec(location.pathname);
                if (match) {
                    // empty
                }
            });
        },
        setup ({ dispatch }) {},
    },
    effects: {
        //获取屏幕宽度
        * changeWidth ({ payload }, { call, put }) {},
        /*
        //获取日历内容
        *getGZT ({ payload }, { call, put }){
            const {data} = yield call(getGZT, payload);
            yield put({ type: 'save', payload: {getGZTData:data} });
        },
        */

        //获取工作任务
        *getworking ({ payload }, { call, put }){
            const {data} = yield call(getworking, payload);
            yield put({ type: 'save', payload: {One:data} });
        },
        //获取工作流任务详情(预案)
        *getworkingList ({ payload }, { call, put }){
            const data = yield call(getworkingList, payload);
            yield put({ type: 'save', payload: {
                fist:data,
                outcomesView:false,
                outcomesView_1:false,
                outcomesView_2:false,
                outcomesView_3:false,
            }});
        },
        //获取处理内容
        *getTaskData ({ payload }, { call, put }){
            const data = yield call(getTaskData, payload);
            if(data.type == 'form_evaluation'){
                data.name = '演练计划对应的题目';
                yield put({ type: 'save', payload: {outcomes:data,outcomesView_1:true,taskId:payload.taskId} });
            } else if(data.type == 'form_record'){
                data.name = '预案整改方案';
                yield put({ type: 'save', payload: {outcomes:data,outcomesView_2:true,taskId:payload.taskId} });
            } else if(data.type == 'form_program'){
                data.name = '整改措施';
                yield put({ type: 'save', payload: {outcomes:data,outcomesView_3:true,taskId:payload.taskId,Allarr:[{}]} });
            } else if(data.type){
                yield put({ type: 'save', payload: {outcomes:data,outcomesView:true,taskId:payload.taskId,contentValue:''} });
            } else {
                Modal.warning({
                    title: '确认完成?',
                    width:240,
                    content: '按esc退出!',
                    okText:"确认完成",
                    onOk () {
                        dispatchApp({type:'postTaskData',payload:{taskId:payload.taskId}});
                    },
                });
            }
        },
        //提交处理内容
        *postTaskData ({ payload }, { call, put }){
            const data = yield call(postTaskData, payload);
            yield put({ type:'getworkingList',payload:{
                processInstanceId:localStorage.getItem('id_working'),
            }});
        },
    },
    reducers: {
        save (state, { payload }) {
            return { ...state, ...payload };
        },
    },
};
